package com.psct.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

import com.psct.R;

public class GalleryAdapter extends BaseAdapter {

	private Context mContext;
	private int imageSize;
	
	private Integer[] mImageIds = {
			// 定义整型数组 即图片源
			R.drawable.cate_01, R.drawable.cate_02, R.drawable.cate_03, R.drawable.cate_04,
			R.drawable.cate_05, R.drawable.cate_06, R.drawable.cate_07, R.drawable.cate_08,
			R.drawable.cate_09, R.drawable.cate_10, R.drawable.cate_11, R.drawable.cate_12, };

	public GalleryAdapter(Context c) {
		// 声明 ImageAdapter
		mContext = c;
		WindowManager windowManager = (WindowManager) this.mContext.getSystemService(Context.WINDOW_SERVICE);
		// 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
		// int xPos =
		imageSize=  windowManager.getDefaultDisplay().getHeight()/5;
	}

	public int getCount() { // 获取图片的个数
		return Integer.MAX_VALUE;
	}

	public Object getItem(int position) {
		// 获取图片在库中的位置
		return position;
	}

	public long getItemId(int position) {
		// 获取图片在库中的位置
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView i = new ImageView(mContext);
		i.setImageResource(mImageIds[position%mImageIds.length]);
		// 给ImageView设置资源
		i.setLayoutParams(new Gallery.LayoutParams(imageSize, imageSize));
		// 设置比例类型
		i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		return i;
	}
}
